﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yule8xCommon.Applib;
using Yule8xCommon.Db;
using Yule8xCommon.Typelib;
using Yule8xModel;
using Yule8xWechat.Applib;

namespace Yule8xWechat.Recharge
{
    public partial class History : System.Web.UI.Page
    {
        WxUserInfoResult wxUser;
        protected decimal recharge_total;
        protected System.Data.DataTable dtList;
        protected int user_id;
        protected void Page_Load(object sender, EventArgs e)
        {
            user_id = RequestUtil.GetInteger("user_id");
            if (RuntimeDataUtil.CheckDebugModel() && user_id > 0)
            {
                wxUser = UserModels.GetWxUserInfo(user_id);
                if (null == wxUser)
                {
                    ResponseUtil.WriteEnd("user_id无效!");
                }
            }
            else
            {
                wxUser = LoginPageBase.GetLoginInfo();
                if (null == wxUser)
                {
                    Response.Redirect(WechatUrls.GetUserInfoUrl("recharge"), true);
                }
            }
            /*
            object loginData = Session["login"];
            if (null != loginData)
            {
                wxUser = loginData as WxUserInfoResult;
            }
            if (null == loginData || null == wxUser)
            {
                Response.Redirect(WechatUrls.GetUserInfoUrl("withdraw"), true);
            }
            */
            int uid = wxUser.user_id;

            string sqlstmt = string.Format("select recharge_amount_total from t_user_finance_statistics where user_id={0}", uid);
            recharge_total = decimal.Parse(DbFactory.Init(AppInfo.conn_yule8x_agent).GetValue(sqlstmt, "0").ToString());
            // 交易类型(1:充值,2:返现;3:提现;4:赠送;5:领取;6:转换)
            // 转换类别(1:钻石(充值);2:泊众房卡(娱乐);3:网狐金豆(游戏))
            sqlstmt = string.Format("select create_time, transform_amount, transform_amount_type, benefactor_game_id, benefactor_game_nickname, amount, status from t_finance_transaction_details where user_id={0} and trade_type = 1 order by id desc", wxUser.user_id);
            dtList = DbFactory.Init(AppInfo.conn_yule8x_agent).ExecuteDataTable(sqlstmt);
        }
    }
}